package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Dish;
import com.itheima.reggie.domain.Setmeal;
import com.itheima.reggie.service.DishService;
import com.itheima.reggie.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

// 套餐模块
@RestController
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    //套餐列表
    @GetMapping("/setmeal/page")
    public ResultInfo findByPage(
            @RequestParam(name = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, String name
    ) {
        //1接收参数
        //2调用service查询
        Page<Setmeal> page = setmealService.findByPage(pageNum, pageSize, name);
        // 3.返回结果
        return ResultInfo.success(page);
    }

    // 新增套餐
    @PostMapping("/setmeal")
    public ResultInfo save(@RequestBody Setmeal setmeal) {
        //1接收参数
        //2调用service新增
        setmealService.save(setmeal);
        //3返回结果
        return ResultInfo.success();
    }

    // 删除套餐
    @DeleteMapping("/setmeal")
    public ResultInfo deleteBatch(@RequestParam List<Long> ids) {//1接收参数
        //2调用service删除
        setmealService.deleteBactch(ids);
        // 3.返回结果
        return ResultInfo.success();
    }

    //套餐起售,停售
    @PostMapping("/setmeal/status/{status}")
    public ResultInfo updatestatus(@PathVariable Integer status, @RequestParam List<Long> ids) {
        setmealService.updatestatus(status, ids);
        return ResultInfo.success();
    }

    /*   //回显
       @GetMapping("/dish/{id}")
       public ResultInfo findById(@PathVariable long id) {
           //接收路径参数
           //2调用service查询
           Dish dish = dishService.findById(id);
           // 3.返回结果
           return ResultInfo.success(dish);
       }*/
    @GetMapping("/setmeal/{id}")
    public ResultInfo findById(@PathVariable long id) {
        //接收路径参数
        //调用service删除
        Setmeal setmeal = setmealService.findById(id);
        //返回结果
        return ResultInfo.success(setmeal);
    }

    //修改菜品
  /*  @PutMapping("/dish")
    public ResultInfo updateById(@RequestBody Dish dish) {// 1.接收put请求参数
        //调用service修改
        dishService.updateById(dish);
        //返回结果
        return ResultInfo.success();*/
    @PutMapping("/setmeal")
    public ResultInfo updateById(@RequestBody Setmeal setmeal) {// 1.接收put请求参数
        //调用service修改
        setmealService.updateById(setmeal);
        //返回结果
        return ResultInfo.success();
        // 根据分类查询菜品列表

    }


}